package jwdt.xadmin.bbs.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.bbs.bean.TBboard;
import jwdt.xadmin.bbs.service.BoardManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/bbs")
public class BoardManageAction extends BaseAction {
	
	private BoardManageService boardManageService = (BoardManageService)app.getBean("boardManageService");
	
	@RequestMapping("/listBoard")
	public Page doList(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TBboard l = (TBboard)f.copy2Class(TBboard.class);
		return m.getWritePage(f, boardManageService.doList(pu, l).toJson());
	}
	
	@RequestMapping("/saveBoard")
	public Page doAddact(Form f, Module m) throws Exception {
		//
		int id = f.getInt("id",0);
		TBboard obj = (TBboard)f.copy2Class(TBboard.class);
		return m.getWritePage(f, boardManageService.doSave(obj, id));
	}
	
	@RequestMapping("/delBoard")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, boardManageService.doDelact(id));
	}
	
	@RequestMapping("/checkBoard")
	public Page doUpdateState(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, boardManageService.doUpdateState(id, "zt="+result));
	}
	
	@RequestMapping("/lockBoard")
	public Page doLockBoard(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, boardManageService.doUpdateState(id, "lockboard="+result));
	}
	
	@RequestMapping("/listBoardForCombox")
	public Page doListForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select id, name from bbs_board ORDER BY id asc", CacheUtil.C0));
	}
	
	@RequestMapping("/boardWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", boardManageService.doLoad(id));
		return m.findPage("/xadmin/bbs/boardWindow");
	}
}
